<?php
App::uses("File", "Utility");
class ElvisComponent extends Component {  
    public function process($filename) {
        //echo $filename;die;
        //$file = new File($filename);
        //pr($file);die;
        $return = array();
        $file = fopen($filename, 'r');
        while (($line = fgetcsv($file,0,"\n")) !== FALSE) {
            $arr = $this->_get_record($line[0]);
            if($arr['transaction']){
                $return[]=$arr  ;
            }
        }
        //if($file->open('r')){
         
        return $return;
    }
    private function _get_record($record) {
        $return = array();
        $record = str_replace("; ", ";", $record);
        $groups = explode(";", $record);
        //foreach ($groups as $group) {
        $group = $groups[0];
        $return['store_long']=  substr($group, 0,12);$group=  str_replace($return['store_long'], "", $group);
        $return['register'] = substr($group, 0,5);$group=  str_replace($return['register'], "", $group);
        $return['date_short']=  substr($group, 0, 9);$group=  str_replace($return['date_short'], "", $group);
        $return['transaction']=$group;
        $return['casheir']=$groups[1];
        $return['date_long']=$groups[2];
        $return['customer_number']=$groups[3];
        $return['store_short']=$groups[4];
        $return['quantity']=$groups[5];
        $return['price']=$groups[6];
        $return['SKU'] = $groups[7];
        $description = array($groups[8],$groups[9],$groups[10],$groups[11],$groups[12],$groups[13],$groups[14],$groups[15],$groups[16],$groups[17]);
        $return['item_description']=  implode("; ", $description);
        $return['card_number']=$groups[18];
        
        return $return;
        //}
    }
}